
package com.core.dao.jdbcmysql;

import com.core.bean.Online;
import com.core.dao.IOnlineDao;
import com.core.dao.jdbcmysql.JdbcBase;
import com.core.utils.GsonUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class OnlineDao extends JdbcBase implements IOnlineDao {

    @Override
    public Online getByUserName(String name) throws Exception {
        throw new Exception("未实现");
    }

    @Override
    public Online queryByToken(String id) throws Exception {
        throw new Exception("未实现");
    }

    @Override
    public int add(Online entity) throws Exception {
        String Sql = "INSERT INTO `lct_online` VALUES(?,?,?,?,?,?,?,?) ";
        Connection connection = getConnection();
        PreparedStatement ps = null;
        try{
            ps.setString(1,entity.getId());
            ps.setString(2, GsonUtils.toJsonStr(entity.getUser()));
            ps.setObject(3,entity.getLoginTime());
            ps.setString(4,entity.getIp());
            ps.setInt(5,entity.getPort());
            ps.setString(6,entity.getDevInfo());
            ps.setString(7,entity.getOs());
            ps.setString(8,entity.getToKen());
            return ps.executeUpdate();
        }catch (Exception e){
            throw e;
        }finally {
            ps.close();
            connection.close();
        }
    }

    @Override
    public int remove(String id) throws Exception {
        throw new Exception("未实现");
    }

    @Override
    public int modify(Online entity) throws Exception {
        return 0;
    }

    @Override
    public Online findEntityById(String id) throws Exception {
        throw new Exception("未实现");
    }
}

